#!/bin/sh
#
# APPNAME - <summary>
#
# chkconfig:    - 80 20
# description:  Clean old records from the primary database tables (7 days old)
# processname:  fts_db_cleaner

# http://fedoraproject.org/wiki/FCNewInit/Initscripts
### BEGIN INIT INFO
# Provides: 
# Required-Start: 
# Required-Stop: 
# Should-Start: 
# Should-Stop: 
# Default-Start: 
# Default-Stop: 
# Short-Description: 
# Description: 
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/sbin/fts_db_cleaner"
prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/fts-records-cleaner

start() {
    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
    if [ ! -f $lockfile ] ; then
    touch "$lockfile" && success || failure        
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
    else
	echo "Already running"
	return $retval
    fi
}

stop() {
    echo -n $"Stopping $prog: "
    # stop it here, often "killproc $prog"
    rm -f "$lockfile" && success || failure     
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        if [ -f $lockfile ]; then
		echo $"${prog} running"
	else
		echo $"${prog} is stopped"	
	fi
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
	;;
    reload)
        # If config can be reloaded without restarting, implement it here,
        # remove the "exit", and add "reload" to the usage message below.
        # For example:
        # status $prog >/dev/null || exit 7
        # killproc $prog -HUP
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
        exit 2
esac
